<template>
  <div class="app-container">
    <el-card>
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="客户姓名">
          <el-input
            v-model="queryParams.applyName"
            placeholder="请输入客户姓名"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="回访状态">
          <el-select
            v-model="queryParams.revisitStatus"
            clearable
            placeholder="请选择回访状态"
            style="width: 240px"
          >
            <el-option
              v-for="dict in follow_up_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="服务开始时间">
          <el-date-picker
            v-model="queryParams.planBeginTime"
            type="date"
            placeholder="选择开始时间"
            value-format="YYYY-MM-DD"
          />~<el-date-picker
            v-model="queryParams.planEndTime"
            type="date"
            placeholder="选择结束时间"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search"
@click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <!--        <el-col :span="1.5">-->
        <!--          <el-button type="primary" plain icon="Plus" @click="add"-->
        <!--          >新增</el-button-->
        <!--          >-->
        <!--        </el-col>-->
        <right-toolbar
          v-model:showSearch="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="postList"
        stripe
        border
        max-height="500"
      >
        <el-table-column
          label="工单编号"
          align="center"
          prop="workOrderCode"
          width="180"
        />
        <el-table-column
          label="客户姓名"
          align="center"
          prop="applyName"
          width="100"
        />
        <el-table-column label="性别" align="center" width="100">
          <template #default="scope">
            <span>
              {{
                sys_user_sex.find((item) => item.value == scope.row.sex)
                  ? sys_user_sex.find((item) => item.value == scope.row.sex)
                      .label
                  : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="年龄" align="center" prop="age" width="100" />
        <el-table-column
          label="联系电话"
          align="center"
          prop="telephone"
          width="150"
        />

        <el-table-column label="服务项目" align="center" prop="name" />
        <el-table-column label="合计金额" align="center" prop="totalPrice" >
          <template #default="scope">
            <span>
              {{
                scope.row.totalPrice.toFixed(2)
              }}
            </span>
          </template>

        </el-table-column>
        <el-table-column
          label="社区站点"
          align="center"
          prop="communitySiteName"
        />
        <el-table-column
          label="服务人员"
          align="center"
          prop="communitySitePersonnelName"
        />
        <el-table-column
          label="服务开始时间"
          align="center"
          prop="planBeginTime"
        />
        <el-table-column
          label="服务结束时间"
          align="center"
          prop="planEndTime"
        />
        <el-table-column
          label="回访状态"
          align="center"
          prop="evaluationAgencyName"
        >
          <template #default="scope">
            <span>
              {{
                follow_up_status.find(
                  (item) => item.value == scope.row.revisitStatus,
                )
                  ? follow_up_status.find(
                      (item) => item.value == scope.row.revisitStatus,
                    ).label
                  : ""
              }}
            </span>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="100"
        >
          <template #default="scope">
            <el-button
              link
              type="primary"
              v-if="scope.row.revisitStatus == '0'"
              @click="handinfo(scope.row)"
              >回访</el-button
            >
            <el-button link type="primary" v-else @click="handinfo(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.limit"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改岗位对话框 -->
  </div>
</template>

<script setup name="TicketDetails">
const { proxy } = getCurrentInstance();
import { listRevisit } from "@/api/order";
const { sys_user_sex, follow_up_status } = proxy.useDict(
  "sys_user_sex",
  "follow_up_status",
);
const router = useRouter();

const showSearch = ref(true);
const loading = ref(true);
const postList = ref([]);

const total = ref(0);

const name = ref("");

const data = reactive({
  form: {},
  queryParams: {
    page: 1,
    limit: 10,
    planEndTime: undefined,
    planBeginTime: undefined,
    applyName: undefined,
    revisitStatus: undefined,
  },
  rules: {},
});

const { queryParams, form, rules } = toRefs(data);

/** 查询岗位列表 */
function getList() {
  if (queryParams.value.planBeginTime > queryParams.value.planEndTime) {
    proxy.$modal.msgError("开始时间不能大于结束时间");
    return false;
  }
  loading.value = true;
  listRevisit(queryParams.value).then((response) => {
    postList.value = response.page.list;
    total.value = response.page.totalCount;
    loading.value = false;
  })
}
function handleQuery() {
  getList();
}
function resetQuery() {
  queryParams.value = {
    page: 1,
    limit: 10,
    planEndTime: undefined,
    planBeginTime: undefined,
    applyName: undefined,
    revisitStatus: undefined,
  };
  getList();
}
function handinfo(data) {
  router.push({
    path: `/ticketManagement/returnVisitManagement/returnTicketDetails/${data.id}/${data.revisitStatus}`,
  });
}

getList();
</script>
